# # 定义函数
# def getPoint():
#     x = 10
#     y = 20
#     return x,y
#
# # 调用函数
# x,y =getPoint()
#
# x = 10
#
# def test1():
#     global x # 声明x是一个全局变量
#     x = 20
#
# test1()
# print(f"x={x}")
#
# # 写一个函数，求n的阶乘（n为正数）
# def factor(n):
#     if n == 1:
#         return 1
#     return n * factor(n-1)
#
# n = 5
# print(f"{n}的阶乘为{factor(5)}")
#
# def test2(a,b,flag=True):
#     if flag:
#         print(f"a+b={a+b}")
#     else:
#         print(f"a-b={a - b}")
#
# test2(2,1)
# test2(2,1,False)
#
# # def test2(a,flag=True,b):
# # def test2(flag=True,a,b):
#
# def test3(x,y):
#     print(f"x={x}")
#     print(f"y={y}")
#
# test3(y=3,x=2)

import threading
import time
import random
from datetime import datetime,timedelta

def task(n: int):
    startTime = datetime.now()
    time.sleep(n)
    endTime = datetime.now()
    print(f"预计用时:{n},实际用时{endTime-startTime}")

def main(n :int):
    threads = []
    #创建线程
    for i in range(0, n):
        x = random.randint(1,15)
        threads.append(threading.Thread(target=task,args=(x,)))
    #启动线程
    for thread in threads:
        thread.start()

    #等待线程
    for thread in threads:
        thread.join()

startTime = datetime.now()
main(200)
endTime = datetime.now()
print(f"等待了：{endTime - startTime}")

